{__NOLAYOUT__}
<html><head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <title>购物车</title>
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" type="text/css" href="/agent/css/flow.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/product_list.css"/>
    <link rel="stylesheet" type="text/css" href="/agent/css/style_jm.css"/>
    <script type="text/javascript" src="/agent/js/jquery.js" ></script>
    <script type="text/javascript" src="/agent/js/layer.js" ></script>
    <script type="text/javascript" src="/agent/js/rem.js" ></script>
</head>
{if $list}
<body class="body_bj">
<form id="formCart" name="formCart" method="post" action="">
    <div class="folw_shopmain">
        <div class="shopmain_title">
            <dl style="border-bottom: 1px solid #eee;">
                <input id="all" type="checkbox" checked="checked" autocomplete="off" class="f_checkbox f_pub_checkbox f_pub_checkbox_1" title="1" style=" margin-top:10px; margin-left:10px;">
                <dt>
                    <a class="shopLink eclipse" href="#">全选</a>
                </dt>
                <dd><a class="shopLink edit_btn" href="javascript:void(0)" name="1">编辑</a></dd>
            </dl>
        </div>
        <div class="item-list">
            {volist name="list" id="data"}
                <div class="inner">
                <input type="checkbox" checked="checked" autocomplete="off" name="selectOne" value="{$data.sid}" id="" class="f_checkbox check-wrapper check-wrapper-1">
                <div class="item_img"><a href="#"><img src="{:imgno($data.image)}"></a></div>

                <div class="goods_desc edit_info_1">
                    <dl>
                        <dt>{$data.cname}</dt>
                    </dl>
                    <div class="price"><span>￥{$data.price}</span> </div>
                    <div class="box">
                        <div>
                            <input class="cut" type="button" value="-" onclick="goods_cut({$data.sid});">
                        </div>
                        <div>
                            <input class="num upnumber" type="number" data-sid="{$data.sid}"  id="number_{$data.sid}" name="number" value="{$data.number}">
                        </div>
                        <div>
                            <input class="add" type="button" value="+" onclick="goods_add({$data.sid});">
                        </div>
                    </div>
                </div>
            </div>
            {/volist}
        </div>
        <a href="#">
            <div class="num edit_box" style="display:none;">删除</div>
        </a>
        <div class="flow_bottom">
            <div class="info"><!-- <em>合计：</em><em style="color: #f3494c;">￥</em><span class="hot" id="cart_amount_desc">0.00</span> --></div>
            <div class="right">
                <input type="button" href="javascript:void();" onclick="selcart_submit();" class="xm-button " value="去结算">
            </div>
        </div>
        <script>
            function selcart_submit()
            {
              var valArr = new Array;
              $(".item-list :checkbox[checked]").each(function(i){
                valArr[i] = $(this).val();
              });
              var fid = valArr.join(',');
              if(!fid)
              {
                layer.open({content:'请选择要结算的商品' , skin: 'msg', time: 2});
                return false;
              }
                window.location.href='/agent/shopping/settlement/ids/'+fid
            }
          $(function(){
            $("#all").click(function(){
              if(this.checked){
                $(".item-list :checkbox").prop("checked", true);
              }else{
                $(".item-list :checkbox").prop("checked", false);
              }
              var valArr = new Array;
              $(".item-list :checkbox[checked]").each(function(i){
                valArr[i] = $(this).val();
              });
              var fid = valArr.join(',');
              checkGoods(fid)
              //sid   购物车ID

            });
            $(".item-list :checkbox").click(function(){
              allchk();
            });
            
            function allchk(){
              var chknum = $(".item-list :checkbox").length;//选项总个数
              var chk = 0;
              $(".item-list :checkbox").each(function () {
                if($(this).prop("checked")==true){
                  chk++;
                }
              });
              if(chknum==chk){
                $("#all").prop("checked",true);
              }else{
                $("#all").prop("checked",false);
              }
            }

            $(".item-list :checkbox").click(function(){
              var valArr = new Array;
              $(".item-list :checkbox[checked]").each(function(i){
                valArr[i] = $(this).val();
              });
              var ids = valArr.join(',');
              checkGoods(ids)
            });



            //删除购物车
            $('.edit_box').click(function() {
              var ids = '';
              if (window.confirm('确定要删除所选商品吗?')) {
                $('.inner').each(function(i) {
                  if ($(this).find('input[name="selectOne"]').prop('checked')) {
                    ids +=  $(this).find('input').val()+',';
                  }
                });
                $.ajax({
                  type:'get',
                  url:'/agent/shopping/delGoods',
                  data:{ids:ids},
                  success:function (data)  {
                    if(data.code == 1 )
                    {
                      $('.inner').each(function(i) {
                        if ($(this).find('input[name="selectOne"]').prop('checked')) {
                          $(this).remove();
                        }
                      });

                    }
                  }
                });
              }
            });
          });
        </script>
        <script>
          $(".upnumber").mouseout(function(){
            var fid = $(this).attr("data-sid");
            var Num = $(this).val();
            upCart(fid,Num);
            checkGoods();//计算金额
          });
          //商品减少  是否选中
          function goods_cut(fid){
            var new_num =$('#number_'+fid).val();
            var Num = parseInt(new_num);
            Num=Num-1;
            upCart(fid,Num);//修改购物车
          }
          //商品增加
          function goods_add(fid){
            var new_num =$('#number_'+fid).val();
            var Num = parseInt(new_num);
            Num=Num+1;
            upCart(fid,Num);
          }
          function upCart(fid,Num) {
            if(Num < 1)
            {
              layer.open({
                content:'数量不能少于1' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
              });
              return false;
            }
            var valArr = new Array;
            $(".item-list :checkbox[checked]").each(function(i){
              valArr[i] = $(this).val();
            });
            var ids = valArr.join(',');
            $.ajax({
              type:'post',
              url:'/agent/shopping/upCart',
              data:{fid:fid,number:Num},
              success:function (data) {
                if(data.code == 1)
                {
                  $('#number_'+fid).val(Num);
                  checkGoods(ids);//计算金额
                }
              }
            });

          }
		  window.onload = function(){
		  	var valArr = new Array;
            $(".item-list :checkbox[checked]").each(function(i){
              valArr[i] = $(this).val();
            });
            var ids = valArr.join(',');
            checkGoods(ids);//计算金额
            $('#all').click(function(){
            		if($(this).prop("checked")==false){
                  $("#cart_amount_desc").html('0');
                }
            });
          }
          // 计算总计
          function checkGoods(ids)
          {
            if(!ids)
            {
              return false
            }
            $.ajax({
              type:'get',
              url:'/agent/shopping/checkGoods',
              data:{ids:ids},
              success:function (data) {
                $("#cart_amount_desc").html(data.data);
              }
            });
          }
        </script>
        <script>
          $('.edit_btn').bind('click', function() {
            if($(this).html()=="编辑"){
              num = $(this).attr("name");
              $(".edit_box").show();
              $(".flow_bottom").hide();
              $(this).html("完成");
            }
            else
            {
            	  window.location.reload();
              num = $(this).attr("name");
              $(".edit_box").hide();
              $(".flow_bottom").show();
              $(this).html("编辑");
              $("#cart_amount_desc").html(0);
            }
          });
        </script>

        </em></em></form>
</body>
{else}
<body style="background-color: #fff;padding: 0 0.3rem;">
<div class="success">
    <img style="width: 100%" src="/agent/img/kong.png"/>
</div>
<p class="welcome">购物车空空如也</p>
<a href="/agent/index">
    <div class="button" style="margin-top: 1.5rem;width: 4.12rem;height: 0.9rem;line-height: 0.9rem;position: unset;">
        马上逛逛
    </div>
</a>
</body>
{/if}
</html>